// scenic-details.js
import { http } from '../../server/http.server'
import { httpRouter } from '../../server/http.router'
import { _ } from '../../libs/underscore/underscore.modified'
var amapFile = require('../../libs/amap-wx.js');
var WxParse = require('../../libs/wxParse/wxParse.js');
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scenic:{},
    loadStatus: true
  },
  onShareAppMessage: function (res) {
    return {
      title: 'Ai导游',
      path: '/pages/index/index',
      success: function (res) { },
      fail: function (res) { }
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //let spotId = 'CN010101';

    console.log("====================");
    console.log("spotId:" + options.spotId);
    this.getSpots(options.spotId);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  navigation: function () {
    wx.openLocation({
      name: this.data.scenic.SpotName,
      address: this.data.scenic.SpotAddress,
      latitude: this.data.scenic.Lat,
      longitude: this.data.scenic.Lng
    })
  },
  /**
   * 获取景点详情
   */
  getSpots: function (spotId) {
    let that = this;
    http.get(httpRouter.spot(spotId)).subscribe({
      next: res => {
        console.log("====================list");
        console.log(res.data.Content);
        that.format(res.data.Content);
      },
      error: err => console.log(err),
      complete: () => console.log('Todos--get completed')
    })
  },
  format: function (data){
    data.TicketTime = data.TicketTime.split("&&&");
    data.Price = data.Price.split("&&&");
    data.Tips = data.Tips.split("&&&");

    data.distance = app.getDistance(data.Lat, data.Lng);
    this.setData({
      scenic: data,
      loadStatus:false
    })
  },
  transform:function(value){
    let list = value.split("&&&");
    let dom="";
    for(var i=0; i<list.length; i++){
      dom += '<div>'+list[i]+'</div>';
    }
    return dom;
  }
})